package com.lr.generatorplus.utils;


import java.util.List;


public class PageResult<T extends List> extends Result<T> {

    /**
     * 总记录数
     */
    private long total;

    /**
     * 总页数
     */
    private long pages;

    public PageResult(int code, String msg, T data, long total, long pages) {
        super(code, msg, data);
        this.total = total;
        this.pages = pages;
    }

    public PageResult(int code, String msg, T data) {
        super(code, msg, data);
    }

    public static <E> PageResult success(List<E> list, long total, long pages) {
        return new PageResult<>(SUCCESS_CODE, SUCCESS_MSG, list, total, pages);
    }

    public static <E> PageResult success(List<E> list) {
        return new PageResult<>(SUCCESS_CODE, SUCCESS_MSG, list);
    }

    public static PageResult fail(int code, String msg) {
        return new PageResult(code, msg, null);
    }

    public static <E> PageResult fail(List<E> list, int code, String msg) {
        PageResult<List<E>> result = new PageResult<List<E>>(code, msg, list);
        return result;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public long getPages() {
        return pages;
    }

    public void setPages(long pages) {
        this.pages = pages;
    }
}
